@<template>
  <div class="left">
    <el-menu
      :default-active="active"
      class="el-menu-vertical-demo"
      @select="selectRouter"
      :collapse="isisCollapse"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      style="height: 100%"
    >
      <div class="left-top text-one">
        <i class="iconfont icon-Vue"></i>
        <span> vue-admin-beautiful-pro</span>
      </div>
      <!-- 实现动态路由 -->
      <div v-for="(item, index) in listRouter" :key="index">
        <el-menu-item :index="item.path" v-if="!item.children">
          <i class="el-icon-s-home"></i>
          <span slot="title">{{ item.name }}</span>
        </el-menu-item>

        <el-submenu index="1" v-else>
          <template slot="title">
            <i class="el-icon-s-finance"></i>
            <span slot="title" style="padding:0px 15px">组件</span>
          </template>
          <el-menu-item-group>
            <el-menu-item
              :index="items.path"
              v-for="(items, childrenIndex) in item.children"
              :key="childrenIndex"
              >{{ items.name }}</el-menu-item
            >
          </el-menu-item-group>
        </el-submenu>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      listRouter: [],
    };
  },
  mounted() {
    this.listRouter = JSON.parse(sessionStorage.getItem("routlist"));
  },
  methods: {
    selectRouter(key) {
      //key表示index的值  就是点哪个就跳转到哪里
      // console.log(key);
      this.$router.push(key);
    },
  },
  computed: {
    isisCollapse: function () {
      return this.$store.state.show;
    },
    active: function () {
      let arr = this.$store.state.routerData;
      let item = arr.find((item) => {
        return item.show == true;
      });
      return item.path;
    },
  },
};
</script>

<style scoped lang="less">
.left {
  height: 100%;
  background-color: #545c64;
  color: #fff;
  font-size: 14px;
  overflow: hidden;
  .left-top {
    width: 180px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    padding-left: 17px;
    i {
      font-size: 30px;
      vertical-align: bottom;
      padding-right: 13px;
    }
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}
.left/deep/.el-menu {
  border: none;
}
</style>